package day6;

import java.util.*;

//测试集合遍历
public class TestIterate {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        Set<String> set = new HashSet<>();
        Map<String,String> map = new HashMap<>();
        list.add("a");
        list.add("b");
        list.add("c");
        list.add("d");
        list.add("e");
        System.out.println("标准for----------------");
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
        System.out.println("增强for----------------");
        for (String s : list){
            System.out.println(s);
            //list.remove(s);   出现并发修改异常
        }
        System.out.println("迭代器----------------");
        Iterator<String> it = list.iterator();
        while (it.hasNext()){
            String s = it.next();
            System.out.println(s);
            //list.remove(s);    出现并发修改异常
            if ("c".equals(s)) it.remove();
        }
        list.remove("a");
        System.out.println(list);
    }
}
